﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using V5_Model;
using V5_BLL;
using V5_Common;
using System.IO;

namespace V5_EShop {
    public class BasicPage : System.Web.UI.Page {
        public ModelConfig config = null;//全站配置管理
        public ModelChannel channel = null;//频道配置管理
        public ModelUser user = null;
        public BLLUser blluser = new BLLUser();

        protected string Action = string.Empty;
        protected string Type = string.Empty;
        public const string AppSettings = "~/Config/KHD.appSettings.config";
        protected string TabSelect1 = "noselect", TabSelect2 = "noselect", TabSelect3 = "noselect", TabSelect4 = "noselect";
        /// <summary>
        /// 网站模板目录
        /// </summary>
        public string TemplatePath {
            get {
                return "Template/" + config.TemplatePath;
            }
        }
        protected override void OnInit(EventArgs e) {
            config = new BLLConfig().GetModel();
            base.OnInitComplete(e);
        }

        //成功 true 失败false
        protected bool check_member_login() {
            if (Request.Cookies["membername"] != null && Request.Cookies["memberid"] != null) {
                int userid = Input.SetInt(Request.Cookies["memberid"].Value);
                user = new BLLUser().GetModel(userid);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 获取图片
        /// </summary>
        /// <param name="picsrc"></param>
        /// <param name="pictype"></param>
        /// <returns></returns>
        public string getPic(object picsrc, string pictype) {
            string str1 = picsrc.ToString();
            switch (pictype.ToLower()) {
                case "l":
                    str1 = Helper.Replace(Helper.Replace(str1, "productm", "productl"),
                        "products", "productl");
                    break;
                case "m":
                    str1 = Helper.Replace(Helper.Replace(str1, "productl", "productm"),
                        "products", "productm");
                    break;
                case "s":
                    str1 = Helper.Replace(Helper.Replace(str1, "productl", "products"),
                        "productm", "products");
                    break;
            }
            return str1;
        }

        /// <summary>
        /// 获取产品信息
        /// </summary>
        /// <param name="oProductID"></param>
        /// <returns></returns>
        public ModelProduct Get_Product(object oProductID) {
            int iProductID = Input.SetInt(oProductID);
            return new BLLProduct().GetModel(iProductID);
        }

        //返回用户信息
        public ModelUser Get_UserInfo(object userid) {
            int id = Input.SetInt(userid);
            if (id > 0) {
                return new BLLUser().GetModel(id);
            } return null;
        }

        protected override void Render(HtmlTextWriter writer) {
            StringWriter sw = new StringWriter();
            HtmlTextWriter htmlw = new HtmlTextWriter(sw);
            base.Render(htmlw);
            htmlw.Flush();
            htmlw.Close();
            string pageContent = sw.ToString();
            pageContent += @"<div align='center'><a href='http://www.v5soft.com' title='v5soft软件提供'>Powered by v5soft.com</a></div>";
            Response.Write(pageContent);
        }
    }
}
